package com.company;

import java.io.*;

public class iotest04 {
    public static void main(String[] args)  {

     method();
        method1();
    }
    public static void method()  {
       // FileInputStream(String name)
       // FileInputStream(File file)
        InputStream in=null;
 try {
     in=new FileInputStream("D:\\WeGame\\1.txt");

     InputStream in1=new FileInputStream(new File("D:\\WeGame\\1.txt"));
     int data=in.read();
     System.out.println(data);
     int data1=in.read();
     System.out.println(data1);
     int data2=in.read();
     System.out.println(data2);
     //没数据读取的永远是-1
     int b=0;
     while ((b=in.read())!=-1){
         System.out.println(b);
     }

 }catch (Exception e){
     e.printStackTrace();
 }finally {
     try {
         in.close();
     } catch (IOException e) {
         e.printStackTrace();
     }
 }

    }
    public static void method1() {
        InputStream in2=null;
        try {
             in2=new BufferedInputStream(new FileInputStream("D:\\WeGame\\1.txt"));
            int data=in2.read();
            System.out.println(data);
            int b=0;
            while ((b=in2.read())!=-1){
                System.out.println(b);
            }
            in2.close();
        }catch (Exception e){
            e.printStackTrace();
        }finally {
            try {
                in2.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }

    }
}

